#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        if(nums.empty()){
            return 0;
        }
        int presum = 1;
        int size = nums.size();
        int temp = nums[0];
        for(int i = 1;i<nums.size();++i){
            //把多出来的置为最大值 
            if(nums[i]==temp){
                ++presum;
                if(presum>=3){
                    nums[i] = INT16_MAX;
                    --size;
                }
            }
            else{
                presum = 1;
                temp = nums[i];
            }
        }
        sort(nums.begin(),nums.end());
        return size;
    }
};

int main(){
    Solution S;
    vector<int> V = {0,0,1,1,1,1,2,3,3};
    cout<<S.removeDuplicates(V)<<endl;
    return 0;
}
